package jmine.tec.utils.reflection.fast.asm;

import java.lang.reflect.Constructor;

import jmine.tec.utils.reflection.fast.FastConstructor;

/**
 * @author takeshi
 */
public abstract class CompiledConstructor implements FastConstructor {

    /**
     * {@inheritDoc}
     */
    public abstract Object build(Object... args) throws Exception;

    /**
     * {@inheritDoc}
     */
    public final int getArity() {
        return this.getParamTypes().length;
    }

    /**
     * @return array de {@link Class}
     */
    public abstract Class<?>[] getParamTypes();

    /**
     * @return {@link Class}
     */
    public abstract Class<?> getDeclaringClass();

    /**
     * {@inheritDoc}
     */
    public Constructor<?> getConstructor() {
        try {
            return this.getDeclaringClass().getConstructor(this.getParamTypes());
        } catch (Exception e) {
            throw new IllegalArgumentException(e);
        }
    }

}
